//
//  FeaturesHeadView.m
//  danpin
//
//  Created by Hongyu Zhang on 15/11/7.
//  Copyright © 2015年 chuangjia. All rights reserved.
//

#import "FeaturesHeadView.h"

#import "viewconfig.h"

#import "ColorsLineView.h"


@implementation FeaturesHeadView


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
 
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(ctx, 0.6, 0.6, 0.6, 0.4);
    CGContextSetLineWidth(ctx, 2.5);
    
    CGContextMoveToPoint(ctx, 30, 0);
    
    
    CGContextAddLineToPoint(ctx,30, self.bounds.size.height);
    
    
    CGContextStrokePath(ctx);
    
    
    [ self initLabels ];
    
    
    float fHeight =20;// _lbFeature1.frame.size.height;
    fHeight += 15;
    
    float fTop = self.bounds.size.height - fHeight - 15;
    
    
    
    
    _lbFeature1.frame = CGRectMake(15, fTop, 80    , fHeight);
    
    fTop +=  - fHeight - 15;
    _lbFeature2.frame = CGRectMake(15, fTop, 80  , fHeight);
    

    fTop +=  - fHeight - 15;
    _lbFeature3.frame = CGRectMake(15, fTop, 80 , fHeight);
    
    
    
    _lineView.frame = CGRectMake(0, self.bounds.size.height-1, self.bounds.size.width/3, 1);


}

- (UILabel*) createLabel:(NSString*)strText index:(int) nIndex
{
    
    UILabel* lb;
    if(lb)
        return lb;
    
    lb = [[UILabel alloc]initWithFrame:CGRectMake(0,0, 20, 20)];
    lb.textAlignment = NSTextAlignmentCenter;
    lb.layer.cornerRadius = 3;
    lb.layer.masksToBounds = YES;
    lb.textColor = [UIColor whiteColor];
 //   lb.backgroundColor = RED_COLOR;//[UIColor greenColor];
    lb.font = FONT(12);
    lb.text = strText;
    lb.alpha = 0.95f;
    
    [self addSubview: lb];
    
    [lb sizeToFit];
    
    
    switch (nIndex) {
        case 2:
        {
            lb.backgroundColor = [UIColor colorWithRed:0.176 green:0.463 blue:0.627 alpha:1];
        }
            break;
            
            case 1:
            
            lb.backgroundColor = [UIColor colorWithRed:0.180 green:0.698 blue:0.427 alpha:1];
            break;
        case 0:
            
            lb.backgroundColor = [UIColor colorWithRed:0.992 green:0.639 blue:0.259 alpha:1];
            break;
            
        default:
            lb.backgroundColor = RED_COLOR;
            break;
    }
    
    return lb;

}

- (void) initLabels
{
    
    
    if(!_lbFeature1)
    {
        _lbFeature1 = [self createLabel:@"全球比价" index:0];
    }
    if(!_lbFeature2)
    {
        _lbFeature2 = [self createLabel:@"一键海淘" index:1];
    }
    if(!_lbFeature3)
    {
        _lbFeature3 = [self createLabel:@"分享赚钱" index:2];
    }
    
    
    if(!_lineView)
    {
        _lineView = [[ColorsLineView alloc]initWithFrame:CGRectZero];
        
        [self addSubview:_lineView];
    }

}



//*/

@end
